﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Iacym.Entities;

namespace Iacym.Repository
{
    public class Persona_ProfesionRepository : MasterRepository, IPersona_ProfesionRepository
    {
        public List<PERSONA_PROFESION> GetAllFromPersonaProfesion()
        {
            var query = from c in context.PERSONA_PROFESION.Include("PROFESION")
                        select c;
            return query.ToList();
        }

        public List<PERSONA_PROFESION> GetFromPersonaProfesionByPersonaId(int id)
        {
            var query = from c in context.PERSONA_PROFESION.Include("PROFESION")
                        where c.PersonaId.Equals(id)
                        select c;
            return query.ToList();
        }

        public void RemovePersonaProfesionByPersonaIdProfesionId(int personaId, int profesionId)
        {
            var existe = context.PERSONA_PROFESION.SingleOrDefault(p => p.ProfesionId.Equals(profesionId) && p.PersonaId.Equals(personaId));

            if (existe != null)
            {
                context.PERSONA_PROFESION.Remove(existe);
                context.SaveChanges();
            }
        }
    }
}
